package com.api.impl;

import java.lang.reflect.Method;

import com.api.client.model.ApiProxyFactory;
import com.api.model.AbstractApi;
import com.api.model.ApiRequestBuilder;

public class ServiceApi extends AbstractApi {

	private final ApiProxyFactory apiFactory;

	private final RequestBuilderFactory requestBuilderFactory;

	public ServiceApi(ApiProxyFactory apiFactory, RequestBuilderFactory requestBuilderFactory) {
		if (apiFactory == null || requestBuilderFactory == null) {
			throw new IllegalArgumentException("ApiFactory and requestBuilderFactory cannot be null");
		}

		this.apiFactory = apiFactory;
		this.requestBuilderFactory = requestBuilderFactory;
	}

	@Override
	public ApiRequestBuilder getRequest(Method method) {
		return requestBuilderFactory.getRequestBuilder(method);
	}

	@Override
	protected <T> T getProxyService(Class<T> serviceClass) {
		return apiFactory.getProxy(serviceClass);
	}
}
